﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AutomationTools;
using System.Text.RegularExpressions;
using AutomationTools.Procedimentos;
using System.Dynamic;
using System.Collections;
using AutomationTools.Procedimentos.Iteracao;
using AutomationTools.Procedimentos.Acao.Transformacao;
using AutomationTools.Procedimentos.Busca;
using AutomationTools.Procedimentos.Leitura;

namespace AutomationToolsSample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            ProcedimentoController controller = new ProcedimentoController();
            controller.Procedimentos.AddRange(
                new IProcedimento[]{
                    new Request("http://intranet/rh.aspx", new ParametrosRequest(
                    new ParametroRequest("ramal", "capella")
                ), Request.EnumFormMethod.GET),
                new ExecutarRegex(@"<table width=""100%"" border=""1"" cellpadding=""3"" cellspacing=""0"">.*?</table>"),
                new Primeiro(
                    new ExecutarRegex(@"<tr>.*?</tr>")
                ),
                new ParaCada(
                    new RegexParseObject<Funcionario>()
                )
            });

            var ret = ((IEnumerable)controller.ExecutarProcedimentos()).Cast<Funcionario>();

            foreach (var item in ret)
            {
                textBox1.Text += "Nome: " + item.Nome + "  Ramal: " + item.Ramal + Environment.NewLine;
            }
            
        }

        public class Funcionario
        {
            [RegexParse("<td>(.*?)&nbsp;</td>", Grupo = 1, Index = 0)]
            public string Nome { get; set; }
            [RegexParse("<td>(.*?)&nbsp;</td>", Grupo = 1, Index = 1)]
            public string Ramal { get; set; }
        }
    }


}
